package com.isoft.c2team3service2.controller;


import com.isoft.c2team3service2.bean.ResponseData;
import com.isoft.c2team3service2.dto.ArtistRegisterDTO;
import com.isoft.c2team3service2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 艺人注册接口（复用UserController的登录相关路径）
 */
@RestController
@RequestMapping("/login/artist")
public class ArtistRegisterController {
    
    @Autowired
    private UserService userService;

    /**
     * 艺人注册接口
     * @param dto 艺人注册参数（包含用户、会员、艺人信息）
     * @return 注册结果
     */
    @PostMapping("/register")
    public ResponseData<Map<String, Object>> artistRegister(@RequestBody ArtistRegisterDTO dto) {
        // 1. 参数校验（核心字段非空判断）
        if (dto.getEmail() == null || dto.getCode() == null || dto.getPassword() == null) {
            return new ResponseData<>(5001, "邮箱、验证码、密码不能为空", null);
        }
        if (dto.getUsername() == null || dto.getUsername().trim().isEmpty()) {
            return new ResponseData<>(5001, "真实姓名不能为空", null);
        }

            // 2. 调用Service层处理注册逻辑
        try {
            Map<String, Object> result = userService.artistRegister(dto);
            // 判断业务是否成功
            if (Boolean.FALSE.equals(result.get("success"))) {
                return new ResponseData<>(400, (String) result.get("message"), result); // 业务错误返回400
            }
            return new ResponseData<>(200, "注册成功", result); // 业务成功返回200
        } catch (Exception e) {
            return new ResponseData<>(500, "系统错误：" + e.getMessage(), null); // 系统错误返回500
        }
    }
}